#ifndef  xRenderScheme_h_h_h_h_h
#define xRenderScheme_h_h_h_h_h


#include "XDefine.h"
#include "xShaderParameter.h"
#include "xShader.h"
#include "xShaderManager.h"
#include "xTexture.h"

namespace XE
{

	class xShader;
	class xTexture;
	class xMaterial;

	class  XClass xRenderScheme
	{

		friend xMaterial;
		friend int  TechniqueDisComp (const void* first,const  void* second);
	
	protected:
		xRenderScheme(float dis,xShaderPtr pShader);
		~xRenderScheme();
public:
		bool  SetTexture(int index,xTexturePtr pTexture);
		xTexturePtr	 GetTexture(int index)const ;
		int GetTexutreNumber() const ;


		xShaderPtr	 GetShader() 
		{
			if(m_pShader.isNull())
			{
				m_pShader= DefaultShader;
			}
			return m_pShader;
		}

		void SetShader(xShaderPtr	 pShader);

		float GetDistance()const {return m_Distance;};


		//-----------shader parameter fun
	    void DestoryParameterMap();


		bool SetConstantValueBySemantic(const xString& SemanticName,float data );

		bool SetConstantValueBySemantic(const xString& SemanticName,int pData);

		bool SetConstantValueBySemantic(const xString& SemanticName, const xMatrix* pData);

		bool SetConstantValueBySemantic(const xString& SemanticName,bool  pData);

		bool SetConstantValueBySemantic(const xString& SemanticName,const  xVector3* pData);

		bool SetConstantValueBySemantic(const xString& SemanticName,const  xColor * pData);

		bool SetConstantValueBySemantic(const xString& SemanticName, const xVector4* pData);

		bool SetConstantValueBySemantic(const  xString& SemanticName, void* pData,UINT size);

		bool SetConstantArrayValueBySemantic(const xString&SemanticName,const float* pData,UINT num);

		bool SetConstantArrayValueBySemantic(const xString&SemanticName,const int* pData,UINT num);

		bool SetConstantArrayValueBySemantic(const xString&SemanticName,const bool* pData,UINT num);

		bool SetConstantArrayValueBySemantic(const xString&SemanticName, const xMatrix* pData,UINT num);

		bool SetConstantArrayValueBySemantic(const xString& SemanticName,const  xVector3* pData,UINT num);

		bool SetConstantArrayValueBySemantic(const xString& SemanticName,const  xColor * pData,UINT num);

		bool SetConstantArrayValueBySemantic(const xString& SemanticName, const xVector4* pData,UINT num);








		xShaderParameter* GetParameterByName(const xString& name);


		bool SetConstantValue(const xString& name,float pData);


		bool SetConstantValue(const xString& name,int pData);

		bool SetConstantValue(const xString& name,DWORD data);


		bool SetConstantValue(const xString& name, const xMatrix* pData);


		bool SetConstantValue(const xString& name,bool  pData);


		bool SetConstantValue(const xString& name,const  xVector3* pData);

		bool SetConstantValue(const xString&name, const xVector2* pData);

		bool SetConstantValue(const xString& name,const  xColor * pData);

		bool SetConstantValue(const xString& name, const xVector4* pData);

		bool SetConstantValue(const  xString& name, void* pData,UINT size);


		bool SetConstantArrayValue(const xString&name,const float* pData,UINT num);


		bool SetConstantArrayValue(const xString&name,const int* pData,UINT num);


		bool SetConstantArrayValue(const xString&name,const bool* pData,UINT num);


		bool SetConstantArrayValue(const xString&name, const xMatrix* pData,UINT num);

		bool SetConstantArrayValue(const xString& name,const  xVector3* pData,UINT num);

		bool SetConstantArrayValue(const xString& name,const  xColor * pData,UINT num);

		bool SetConstantArrayValue(const xString& name, const xVector4* pData,UINT num);



		bool UpdateParameter(XRenderSystem* pRender);




		xShaderParameter*  CreateParameter\
			(const xString& name,const xString& SemanticName ,XSHADERPARAMETER_TYPE ParaType,UINT size,const ParaMap& annoMap);


		xShaderParameter* CreateParameter(const xString& name,XSHADERPARAMETER_TYPE ParaType,UINT size);

	bool HasAutoContantParameter(const xString& SemanticName);

		


		//-------------------shader parameter end=-----------------------



		protected:
			HRESULT BuildConstantParamterTable();

			//HRESULT AddParameter(const xShaderParameter& para);





	protected:
		float m_Distance;
		xShaderPtr m_pShader;
		xTexturePtr m_Textrue[MaxTextureLevel];

		xShaderParameterMap  m_ParameterMap;

		xAutoConstantParameterVector m_AutoParameterVector;

	};

	int TechniqueDisComp(const void * first,const void * second);






}



#endif